package pers.fulsun.demo.springcloud.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pers.fulsun.demo.springcloud.entity.User;
import pers.fulsun.demo.springcloud.service.impl.UserServiceImpl;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>编写接口路径为/test/feign的接口，供内部调用
 *
 * @author fulsun
 * @date 2021/9/11
 */
@RestController
public class FeignTestController {
    @Autowired
    private UserServiceImpl userService;
    @GetMapping("/test/feign/{id}")
    public Map getUser(@PathVariable("id") Long id) throws InterruptedException {
        // 服务提供方8001故意写暂停程序
        Thread.sleep(3000);
        Map result = new HashMap();
        result.put("id", id);
        result.put("name", "xiaoming");
        result.put("sex", "male");
        result.put("age", 12);
        return result;
    }

    /**
     * 新增User,用于测试分布式事务
     * @param user
     * @return
     */
    @PostMapping("/test/feign/user")
    public Boolean addUser(@RequestBody User user) {
        this.userService.addUser(user);
        return Boolean.TRUE;
    }
}